<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<style>
    img {
    position: absolute;
    top: 0;
    left: 0;    
    width: 100px;
    height: 100px;
    }
</style>
<body>
    <img src="./img//mousemove1.png" alt="">

    <script>

        var pic = document.querySelector('img');
        document.addEventListener('mousemove', function(e) {
        var x = e.pageX;
        var y= e.pageY;
        pic.style.top =y-40+'px';
        pic.style.left =x-50 +'px';
        var r = Math.floor(Math.random() * 256);
            var g = Math.floor(Math.random() * 256);
            var b = Math.floor(Math.random() * 256);
            pic.style.backgroundColor = 'rgb('+r+','+g+','+b+')';
    });
        //点击事件
         document.addEventListener('click', function() {
            //随机颜色
            var r = Math.floor(Math.random() * 256);
            var g = Math.floor(Math.random() * 256);
            var b = Math.floor(Math.random() * 256);
            pic.style.backgroundColor = 'rgb('+r+','+g+','+b+')';
                });


    </script>
</body>
</html>